<?php
include 'secure/core.php';
include 'header.php';
include 'left.php';
$sql = "SELECT * FROM `payments` WHERE `status` = 'pending'";          
$res = $ado->exec($sql);
$fetched_rows = mysql_num_rows($res);
?>
		<div id="right">
		<div class="section">
		<?php if($_GET['msg'] == '1') { ?>
		<div class="message green"><span><b>Success</b>: Payment has been marked as sent and the user has been notified.</span></div>
		<?php } ?>
		<?php if($_GET['msg'] == '2') { ?>
		<div class="message red"><span><b>Error</b>: There was a problem marking this payment as sent.</span></div>
		<?php } ?>
				<div class="box">
					<div class="title">
						View pending payments
						<span class="hide"></span>
					</div>
					<div class="content">
						<div class="dataTables_wrapper"><div></div><table cellspacing="0" cellpadding="0" border="0"> 
							<thead> 
								<tr>
								  <th rowspan="1" colspan="1" style="width: 153px; ">Username</th>
								  <th rowspan="1" colspan="1" style="width: 97px; ">Payment</th>
								  <th rowspan="1" colspan="1" style="width: 171px; ">Date</th>
								  <th rowspan="1" colspan="1" style="width: 158px; ">Paypal</th>
								  <th rowspan="1" colspan="1" style="width: 79px; ">Action</th></tr>
							</thead>
							
						<tbody>  <?php 
						if($fetched_rows>0){
						while($row_array = mysql_fetch_assoc($res)){ 
						$id = $row_array['userid']; ?>
						                <tr> 
									<td><?php echo $users->getUsername($id); ?></td>
									<td>$<?php echo $row_array['amount']; ?></td>
									<td><?php echo $row_array['request_date']; ?></td>
									<td><?php echo $row_array['payment_email'] ;?></td>
									<td><a href="pay.php?id=<?php echo $row_array['id']; ?>">Mark Sent</a></td>									
								</tr>
							<?php }} else { ?>
							<tr> 
								 <td colspan="5">Currently no pending payments</td>									
							</tr>
							<?php } ?>
						</tbody>
						
				            </table>

</div>
					        </div>
					</div>
				</div>
			</div>
		</div>

<div id="footer">
			<div class="split">Copyright &#169; 2012 - <a href="index.php">Paid4Upload</a>.</div>
			<div class="split right"><a href="http://www.paid4upload.com/forums">Forums</a> | <a href="tos.php">Terms of Service</a> | <a href="dmca.php">DMCA</a></div>
		</div>
	</div>
</div>

</body>
<?php
     function check_integer($which) {
        if(isset($_REQUEST[$which])){
            if (intval($_REQUEST[$which])>0) {
                //check the paging variable was set or not, 
                //if yes then return its number:
                //for example: ?page=5, then it will return 5 (integer)
                return intval($_REQUEST[$which]);
            } else {
                return false;
            }
        }
        return false;
    }//end of check_integer()

    function get_current_page() {
        if(($var=check_integer('page'))) {
            //return value of 'page', in support to above method
            return $var;
        } else {
            //return 1, if it wasnt set before, page=1
            return 1;
        }
    }//end of method get_current_page()

    function doPages($page_size, $thepage, $query_string, $total=0) {
        
        //per page count
        $index_limit = 1;

        //set the query string to blank, then later attach it with $query_string
        $query='';
        
        if(strlen($query_string)>0){
            $query = "&amp;".$query_string;
        }
        
        //get the current page number example: 3, 4 etc: see above method description
        $current = get_current_page();
        
        $total_pages=ceil($total/$page_size);
        $start=max($current-intval($index_limit/2), 1);
        $end=$start+$index_limit-1;

        echo '<div class="paging">';

        if($current==1) {
            echo '<span class="prn">&lt; Previous</span>&nbsp;';
        } else {
            $i = $current-1;
            echo '<a href="'.$thepage.'?page='.$i.$query.'" class="prn" rel="nofollow" title="go to page '.$i.'">&lt; Previous</a>&nbsp;';
            echo '<span class="prn">...</span>&nbsp;';
        }

        if($start > 1) {
            $i = 1;
            echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a>&nbsp;';
        }

        for ($i = $start; $i <= $end && $i <= $total_pages; $i++){
            if($i==$current) {
                echo '<span>'.$i.'</span>&nbsp;';
            } else {
                echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a>&nbsp;';
            }
        }

        if($total_pages > $end){
            $i = $total_pages;
            echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a>&nbsp;';
        }

        if($current < $total_pages) {
            $i = $current+1;
            echo '<span class="prn">...</span>&nbsp;';
            echo '<a href="'.$thepage.'?page='.$i.$query.'" class="prn" rel="nofollow" title="go to page '.$i.'">Next &gt;</a>&nbsp;';
        } else {
            echo '<span class="prn">Next &gt;</span>&nbsp;';
        }
        
        //if nothing passed to method or zero, then dont print result, else print the total count below:
        if ($total != 0){
            //prints the total result count just below the paging
            echo '<p id="total_count">(total '.$total.' records)</p></div>';
        }}?>
         //end of method doPages()

</html> 